package adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.boltshow.R;
import com.example.administrator.boltshow.ShopActivity;

import org.xutils.x;

import java.util.List;

import model.HotMonkeyModel;

/**
 * Created by Administrator on 2016/8/29.
 */
public class SpecialAdapter extends RecyclerView.Adapter<SpecialAdapter.SpecialViewHolder> {

    private List<HotMonkeyModel.DataBean> mData;
    private Context mContext;
    private String specialId;

    public SpecialAdapter(List<HotMonkeyModel.DataBean> mData,Context mContext,String specialId){
        this.mData = mData;
        this.mContext = mContext;
        this.specialId = specialId;
    }

    @Override
    public SpecialViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.special_rv_cardview,null);
        SpecialViewHolder holder = new SpecialViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(SpecialViewHolder holder, int position) {
        final HotMonkeyModel.DataBean dataBean = mData.get(position);
        x.image().bind(holder.iv_show,dataBean.getImg320url());
        holder.tv_new_money.setText("¥"+dataBean.getCrazyPrice().split("\\.")[0]);
        holder.tv_old_money.setText("¥"+dataBean.getShopPrice().split("\\.")[0]);
        holder.tv_discount.setText(dataBean.getDiscount()+"闪折");
        holder.tv_flashPrice.setText(dataBean.getFlashPrice());
        holder.tv_goodsName.setText(dataBean.getGoodsName());
        holder.iv_show.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, ShopActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("goodsid",dataBean.getGoodsId()+"");
                bundle.putString("linkid",specialId);
                intent.putExtra("bundle",bundle);
                mContext.startActivity(intent);
            }
        });

    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }


    static class SpecialViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_show;
        private TextView tv_new_money,tv_old_money,tv_discount,tv_flashPrice,tv_goodsName;

        public SpecialViewHolder(View itemView) {
            super(itemView);
            iv_show = (ImageView) itemView.findViewById(R.id.iv_special_item_show);
            tv_new_money = (TextView) itemView.findViewById(R.id.tv_special_item_new_money);
            tv_old_money = (TextView) itemView.findViewById(R.id.tv_special_item_old_money);
            tv_discount = (TextView) itemView.findViewById(R.id.tv_special_item_discount);
            tv_flashPrice = (TextView) itemView.findViewById(R.id.tv_special_item_flashPrice);
            tv_goodsName = (TextView) itemView.findViewById(R.id.tv_special_item_goodsName);

        }
    }
}
